package com.czjtxy.extraTerm.daoImpl;

import com.czjtxy.extraTerm.dao.BaseDao;
import com.czjtxy.extraTerm.util.EmJDBCInfo;

import java.sql.*;

/**
 * @program: staff-house
 * @author: MingYi
 * @create: 2021/07/01 09:52
 */
public class BaseDaoImpl implements BaseDao {
    public Connection con;
    public PreparedStatement ps;
    public ResultSet rs;

    @Override
    public void openDB() throws ClassNotFoundException, SQLException {
        //        打开数据库
        Class.forName(EmJDBCInfo.JDBC_DRIVER.getInfo());
        con = DriverManager.getConnection(EmJDBCInfo.DB_URL.getInfo(), EmJDBCInfo.USER.getInfo(), EmJDBCInfo.PASS.getInfo());
    }

    @Override
    public void closeResource() throws SQLException {
        if (con != null) {
            con.close();
        }
        if (ps != null) {
            ps.close();
        }
        if (rs != null) {
            rs.close();
        }
    }
}
